/*
 * list.c
 *
 *  Created on: Jul 4, 2008
 *      Author: Carlos Oliveira
 */

#include "list.h"

#include <stdlib.h>

List *list_new()
{
	List *l = (List*)malloc(sizeof(List));
	if (!l) return 0;
	l->size = 0;
	l->head.next = 0;
	l->last = &l->head;
	return l;
}

void list_delete(List *l)
{
	ListNode *ln = l->head.next;
	while (ln)
	{
		ListNode *tmp = ln;
		ln = ln->next;
		free(tmp);
	}
	free(l);
}

int list_add(List *l, void *elem)
{
	ListNode *node = (ListNode*)malloc(sizeof(ListNode));
	if (!node) return 0;
	node->content = elem;
	node->next = 0;
	l->last->next = node;
	l->last = node;
	l->size++;
	return 1;
}

ListNode *list_firstNode(List *l)
{
	return l->head.next;
}
